/* condition.c
 * test syscall about condition 
 */

#include "syscall.h"

int condition;
int lock;
int rv;

void signal() {
    rv = AcquireLock(lock);
    Write("in condition: AcquireLock\n", 26, ConsoleOutput);
    rv = SignalCV(lock, condition);
    Write("in condition: SignalCV\n", 23, ConsoleOutput);
    rv = ReleaseLock(lock);
    Write("in condition: ReleaseLock\n", 26, ConsoleOutput);
    Exit(0);
}

int main()
{
    condition = CreateCV("testCondition", 13);
    lock = CreateLock("testLock", 8);
    rv = AcquireLock(lock);
    Fork(signal);
    Write("condition: AcquireLock\n", 23, ConsoleOutput);
/*    printf ("AcquireLock rv: %d\n", rv); */
    rv = WaitCV(lock, condition);
    Write("condition: WaitCV\n", 18, ConsoleOutput);
    
    rv = ReleaseLock(lock);
/*    printf ("ReleaseLock rv: %d\n", rv); */
    Write("condition: ReleaseLock\n", 23, ConsoleOutput);
    rv = DeleteLock(lock);
    Write("condition: DeleteLock\n", 22, ConsoleOutput);
/*    printf ("DeleteLock rv: %d\n", rv); */
    Exit(0);
    return 0;
}
